#define _CRT_SECURE_NO_WARNINGS 1
#include<iostream>
#include<vector>
#include<tuple>
using namespace std;

class Solution {
public:
    int edgeScore(vector<int>& edges) {
        int n = edges.size();
        vector<long long> mp(n);
        for (int i = 0; i < n; ++i)
        {
            mp[edges[i]] += i;
        }
        int ans = 0;
        for (int i = 0; i < n; ++i)
        {
            if (mp[i] > mp[ans]) ans = i;
        }
        return ans;
    }

    string longestPalindrome(string s) {
        int n = s.size(), ans = 0;
        if (n < 2) return s;
        vector<vector<int>> dp(n, vector<int>(n));
        for (int i = 0; i < n; ++i)
            dp[i][i] = true;
        int maxLen = 1, begin = 0;
        for (int L = 2; L <= n; ++L)
        {
            for (int i = 0; i < n; ++i)
            {
                int j = L + i - 1;
                if (j >= n) break;
                if (s[i] != s[j]) dp[i][j] = 0;
                else
                {
                    if (j - i < 3) dp[i][j] = 1;
                    else dp[i][j] = dp[i + 1][j - 1];
                }
                if (dp[i][j] && j - i + 1 > maxLen)
                {
                    maxLen = j - i + 1;
                    begin = i;
                }
            }
        }
        return s.substr(begin, maxLen);
    }

    int reverse(int x) {
        int rev = 0;
        while (x != 0)
        {
            if (rev<INT_MIN / 10 || rev>INT_MAX / 10) return 0;
            int digit = x % 10;
            x /= 10;
            rev = rev * 10 + digit;
        }
        return rev;
    }

    int numDecodings(string s) {
        /*int n = s.size();
        vector<int> dp(n);
        dp[0] = s[0] != '0';
        if (n == 1) return dp[0];
        if (s[0] != '0' && s[1] != '0') dp[1] += 1;
        int t = (s[0] - '0') * 10 + s[1] - '0';
        if (t >= 10 && t <= 26) dp[1] += 1;
        for (int i = 2; i < n; ++i)
        {
            if (s[i] != '0') dp[i] += dp[i - 1];
            t = (s[i - 1] - '0') * 10 + s[i] - '0';
            if (t >= 10 && t <= 26) dp[i] += dp[i - 2];
        }
        return dp[n - 1];*/

        /*int n = s.size();
        vector<int> dp(n + 1);
        dp[0] = 1;
        dp[1] = s[0] != '0';
        for (int i = 2; i <= n; ++i)
        {
            if (s[i - 1] != '0') dp[i] += dp[i - 1];
            int t = (s[i - 2] - '0') * 10 + s[i - 1] - '0';
            if (t >= 10 && t <= 26) dp[i] += dp[i - 2];
        }
        return dp[n];*/

        int n = s.size();
        int a = 0, b = 1, c;
        for (int i = 1; i <= n; ++i)
        {
            c = 0;
            if (s[i - 1] != '0') c += b;
            if (i > 1 && s[i - 2] != '0' && ((s[i - 2] - '0') * 10 + s[i - 1] - '0' <= 26)) c += a;
            tie(a, b) = { b,c };
        }
        return c;
    }
};